Skip to content

HexValidator

Base classes

Name Children Inherits
Validator
prettyqt.gui.validator

⋔ Inheritance diagram

graph TD
  3721179600["validators.HexValidator"]
  422589614["gui.Validator"]
  1804432572["gui.ValidatorMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  49520861["QtGui.QValidator"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  422589614 --> 3721179600
  1804432572 --> 422589614
  3227531497 --> 1804432572
  2751680898 --> 3227531497
  49520861 --> 422589614
  3984060476 --> 49520861
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 DocStrings

Bases: Validator

Validator which checks for hexadecimal values.

Source code in prettyqt/validators/hexvalidator.py
class HexValidator(gui.Validator):
    """Validator which checks for hexadecimal values."""

    ID = "hex"

    def __init__(self, maximum: int | None = None, parent=None):
        super().__init__(parent)
        self._maximum = maximum

    def __eq__(self, other: object):
        return isinstance(other, HexValidator) and other._maximum == self._maximum

    def validate(self, text: str, pos: int = 0) -> tuple[gui.QValidator.State, str, int]:
        try:
            val = int(text, 0)
        except ValueError:
            return self.State.Intermediate, text, pos
        if self._maximum is not None and val > self._maximum:
            return self.State.Invalid, text, pos
        return self.State.Acceptable, text, pos

:fa-brands-github: Show source on GitHub